-
Notifications
You must be signed in to change notification settings - Fork 184
Go back to using ref callback instead of useImperativeHandle #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
workflow: benchmarks/sizeComparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.
|
workflow: benchmarks/perf (native)Comparison of performance test results, measured in operations per second. Larger is better.
|
packages/react-strict-dom/src/native/modules/useStrictDOMElement.js
Outdated
Show resolved
Hide resolved
3cb0a57
to
083f2a6
Compare
const elementCallback = useElementCallback( | ||
React.useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need useElementCallback
here.
The useCallback
already has ref
as a dependency, which means the function returned by useCallback
will already be invalidated if ref
changes. And when that new function is passed into the native component's ref
prop below, it will naturally detach the previous one and attach the new one.
packages/react-strict-dom/src/native/modules/useStrictDOMElement.js
Outdated
Show resolved
Hide resolved
083f2a6
to
95ab62e
Compare
We shouldn't create an object if the underlying node is null, as this handle is meant to emulate the node but can't proxy methods if none exist. Since useImperativeHandle isn't reset when the underlying node changes, we go back to using ref callbacks. Rather than mutating the underling node, we create a new object that wraps the relevant fields.
95ab62e
to
d9f8e39
Compare
We shouldn't create an object if the underlying node is null, as this handle is meant to emulate the node but can't proxy methods if none exist.